package service;

import facade.ConectionFactory;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class CreateConectionJPA implements ConectionFactory{

    private EntityManager em;
    private EntityManagerFactory emf;

    public CreateConectionJPA() {
    }

    public EntityManager getEm() {
        return em;
    }

    public EntityManagerFactory getEmf() {
        return emf;
    }

    public EntityManager create() {
        String salida = "exito";
        try {
            emf = Persistence.createEntityManagerFactory("AppServicePU", System.getProperties());
            em = emf.createEntityManager();
            return em;
        } catch (Exception e) {
            if (em == null) {
                salida = "fracaso";
                return null;
            }
        }
        return em;
    }
}
